package com.kingzoder.food.common.base.page;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.util.CollectionUtils;

/**
 * @author 轩辕铮
 */
public class PageHelper {

    public static Page convertPageByQuery(PageQuery pageQuery) {
        Page page = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize());
        if (!CollectionUtils.isEmpty(pageQuery.getBaseSortFields())) {
            pageQuery.getBaseSortFields()
                    .forEach(e -> page.addOrder(e.isAsc() ? OrderItem.asc(e.getField()) :
                            OrderItem.desc(e.getField())));
        }
        return page;
    }
}
